package com.mbyte.easy.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mbyte.easy.admin.entity.*;
import com.mbyte.easy.admin.mapper.VideoMapper;
import com.mbyte.easy.admin.service.*;
import com.mbyte.easy.common.constant.*;
import com.mbyte.easy.common.controller.BaseController;
import com.mbyte.easy.common.web.AjaxResult;
import com.mbyte.easy.security.entity.SysUser;
import com.mbyte.easy.security.mapper.SysUserRolesMapper;
import com.mbyte.easy.security.service.IUserService;
import com.mbyte.easy.util.DateUtil;
import com.mbyte.easy.util.OssFileUtils;
import com.mbyte.easy.util.PageInfo;
import com.mbyte.easy.util.Utility;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.mbyte.easy.common.constant.StatusConstant.*;
import static com.mbyte.easy.common.constant.StatusRecordVideo.STATUS_PPT_AUDIO_AUVELEADER_SEND;
import static com.mbyte.easy.common.constant.StatusRecordVideo.STATUS_PPT_AUDIO_AUVEREADER_SEND;

/**
* <p>
* 前端控制器
* </p>
* @author lp
* @since 2019-03-11
*/
@Slf4j
@Controller
@RequestMapping("/admin/audio")
public class AudioController extends BaseController {

    private String prefix = "admin/audio/";

    @Autowired
    private IAudioService audioService;

    @Autowired
    private IDraftService draftService;

    @Autowired
    private ICheckService checkService;

    @Autowired
    private IAllotService allotService;

    @Autowired
    private IGroupService groupService;


    @Autowired
    private IUserService userService;

    @Autowired
    private VideoMapper videoMapper;

    @Autowired
    private SysUserRolesMapper sysUserRolesMapper;
    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    /**
     * 查询列表
     *
     * @param model
     * @param pageNo
     * @param pageSize
     * @param audio
     * @return
     */
    @RequestMapping("audio")
    public String index(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<Audio>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<Audio>();
        if (!ObjectUtils.isEmpty(audio.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id", audio.getDraftId());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioUrl())) {
            queryWrapper = queryWrapper.like("audio_url", audio.getAudioUrl());
        }
        if (!ObjectUtils.isEmpty(audio.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time", audio.getSubmitTime());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioPerson())) {
            queryWrapper = queryWrapper.like("audio_person", audio.getAudioPerson());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioLength())) {
            queryWrapper = queryWrapper.like("audio_length", audio.getAudioLength());
        }
        if (!ObjectUtils.isEmpty(audio.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code", audio.getStatusCode());
        }
        if (!ObjectUtils.isEmpty(audio.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete", audio.getIsDelete());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.lambda().between(Audio::getSubmitTime, DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        IPage<Audio> pageInfo = audioService.page(page, queryWrapper);
        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("searchInfo", audio);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix + "list";
    }

    /**
     * 添加跳转页面
     *
     * @return
     */
    @GetMapping("addBefore")
    public String addBefore() {
        return prefix + "add";
    }

    /**
     * 添加
     *
     * @param audio
     * @return
     */
    @PostMapping("add")
    @ResponseBody
    public AjaxResult add(Audio audio) {
        return toAjax(audioService.save(audio));
    }

    /**
     * 添加跳转页面
     *
     * @return
     */
    @GetMapping("editBefore/{id}")
    public String editBefore(Model model, @PathVariable("id") Long id) {
        model.addAttribute("audio", audioService.getById(id));
        return prefix + "edit";
    }

    /**
     * 添加
     *
     * @param audio
     * @return
     */
    @PostMapping("edit")
    @ResponseBody
    public AjaxResult edit(Audio audio) {
        return toAjax(audioService.updateById(audio));
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @GetMapping("delete/{id}")
    @ResponseBody
    public AjaxResult delete(@PathVariable("id") Long id) {
        return toAjax(audioService.removeById(id));
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @PostMapping("deleteAll")
    @ResponseBody
    public AjaxResult deleteAll(@RequestBody List<Long> ids) {
        return toAjax(audioService.removeByIds(ids));
    }

    /**
     * @Author 张雪
     * @Description 音视频校对组长--待分配音频
     * @Date 2019/12/9 20:08
     **/
    @RequestMapping("unAllot")
    public String overrideIdendex(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(audio.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id", audio.getDraftId());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioUrl())) {
            queryWrapper = queryWrapper.like("audio_url", audio.getAudioUrl());
        }
        if (!ObjectUtils.isEmpty(audio.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time", audio.getSubmitTime());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioPerson())) {
            queryWrapper = queryWrapper.like("audio_person", audio.getAudioPerson());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioLength())) {
            queryWrapper = queryWrapper.like("audio_length", audio.getAudioLength());
        }
        if (!ObjectUtils.isEmpty(audio.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code", audio.getStatusCode());
        }
        if (!ObjectUtils.isEmpty(audio.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete", audio.getIsDelete());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.between("ta.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        queryWrapper.eq("ta.status_code", StatusPPTAudio.STATUS_AUDIO_AUVELEADER_SUCCESS);//1014
        queryWrapper.lambda().orderByDesc(Audio::getCreateTime);
        IPage<Audio> pageInfo = audioService.listPage(page, queryWrapper);
        PageInfo pageInfo1 = new PageInfo(pageInfo);
        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("searchInfo", audio);
        model.addAttribute("pageInfo", pageInfo1);
        String currentUsername = Utility.getCurrentUsername();
       // log.info("登录用户名  -> {}", currentUsername);
        return prefix + "leader/unAllot";
    }

    /**
     * @Author 张雪
     * @Description // 已分配音频到音视频校对人
     * @Date 2019/12/9 20:08
     **/
    @RequestMapping("alloted")
    public String overIndex(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(audio.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id", audio.getDraftId());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioUrl())) {
            queryWrapper = queryWrapper.like("audio_url", audio.getAudioUrl());
        }
        if (!ObjectUtils.isEmpty(audio.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time", audio.getSubmitTime());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioPerson())) {
            log.info(audio.getAudioPerson());
            queryWrapper = queryWrapper.like("audio_person", audio.getAudioPerson());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioLength())) {
            queryWrapper = queryWrapper.like("audio_length", audio.getAudioLength());
        }
        if (!ObjectUtils.isEmpty(audio.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code", audio.getStatusCode());
        }
        if (!ObjectUtils.isEmpty(audio.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete", audio.getIsDelete());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.between("ta.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        queryWrapper.lambda().orderByDesc(Audio::getCreateTime);

        SysUser sysUser = audioService.getUserByUserName(Utility.getCurrentUsername());
        List<Allot> groupByUserId = audioService.getAllotDraftIdByUserId(sysUser.getId());
        if (groupByUserId.size() != 0) {
            QueryWrapper<Video> queryWrapper1 = new QueryWrapper<>();

            queryWrapper.in("ta.draft_id",groupByUserId.stream().map(Allot::getDraftId).collect(Collectors.toList()));
            queryWrapper.eq("ta.status_code", STATUS_PPT_AUDIO_AUVELEADER_SEND);//1017
            IPage<Audio> pageInfo = audioService.pageList(page, queryWrapper);

            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "leader/alloted";
        }else {
            queryWrapper.lambda().eq(Audio::getStatusCode, StatusWriter.ERROR);
            IPage<Audio> pageInfo = audioService.page(page, queryWrapper);


            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "leader/alloted";
        }
    }

    /**
     * @Author 张雪
     * @Description 点击跳转到leader/allot.html--音频
     *   分配音频
     * @Date 2019/12/9 11:08
     **/
    @RequestMapping("allotBefore")
    public String allotBefore(Model model,String ids) {

        SysUser sysUser = audioService.getUserIdByUserName(Utility.getCurrentUsername());
        List<Long> childrenId = audioService.getChildrenIdByParentId(sysUser.getId());
        Map<Integer,String> map = new HashMap<>();
        for (int i = 0; i < childrenId.size(); i++) {
            SysUser children = userService.selectByPrimaryKey(childrenId.get(i));
            List<com.mbyte.easy.security.entity.SysRole> childrenRoles = children.getRoles();
            for (com.mbyte.easy.security.entity.SysRole childrenRole : childrenRoles) {
                if (SysRole.VIDEO_PROOFREADER.equals(childrenRole.getId())){
                    map.put(i,draftService.getUserNameByUserId(childrenId.get(i)).getUsername());
                }
            }
        }
        model.addAttribute("username",map);
        model.addAttribute("ids",ids);
        return prefix + "leader/allot";

    }

    /**
     * @Author 张雪
     * @Description 点击跳转到worker/allot.html--音频
     * @Date 2019/12/9 11:08
     **/
    @RequestMapping("ToWorker")
    public String ToWorker(Model model, String ids) {
//        String username = Utility.getCurrentUsername();
//        List<SysUser> workers = audioService.selectAllWorker(username);
//        List<String> userNameList = workers.stream().map(SysUser::getUsername).collect(Collectors.toList());
//        model.addAttribute("usernameList", userNameList);
//        log.info("allotBefore ids-->{}", ids);
//        model.addAttribute("idsBus", ids);

        String username = Utility.getCurrentUsername();
        SysUser sysUser = audioService.getUserIdByUserName(username);
        List<Long> childrenId = audioService.getChildrenNameByChildrenIdAudio(sysUser.getId());
        Map<Integer,String> map = new HashMap<>();
        for (int i = 0; i < childrenId.size(); i++) {
            SysUser children = userService.selectByPrimaryKey(childrenId.get(i));
            List<com.mbyte.easy.security.entity.SysRole> childrenRoles = children.getRoles();
            for (com.mbyte.easy.security.entity.SysRole childrenRole : childrenRoles) {
                if (SysRole.AUDIO_VISUAL_PRODUCER.equals(childrenRole.getId())){
                    map.put(i,draftService.getUserNameByUserId(childrenId.get(i)).getUsername());
                }
            }
        }
        model.addAttribute("username",map);
        model.addAttribute("ids",ids);

        return prefix + "worker/allot";
    }

    /**
     * @Author 张雪
     * @Description 待分配到制作人音频
     * @Date 2019/12/9 20:08
     **/
    @RequestMapping("unAllotToMaker")
    public String unAllotToMaker(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(audio.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id", audio.getDraftId());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioUrl())) {
            queryWrapper = queryWrapper.like("audio_url", audio.getAudioUrl());
        }
        if (!ObjectUtils.isEmpty(audio.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time", audio.getSubmitTime());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioPerson())) {
            queryWrapper = queryWrapper.like("audio_person", audio.getAudioPerson());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioLength())) {
            queryWrapper = queryWrapper.like("audio_length", audio.getAudioLength());
        }
        if (!ObjectUtils.isEmpty(audio.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code", audio.getStatusCode());
        }
        if (!ObjectUtils.isEmpty(audio.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete", audio.getIsDelete());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.lambda().between(Audio::getSubmitTime, DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        queryWrapper.lambda().orderByDesc(Audio::getCreateTime);
        SysUser sysUser = audioService.getUserByUserName(Utility.getCurrentUsername());
        List<Allot> groupByUserId = audioService.getDraftByAllotnoId(sysUser.getId());
        if (groupByUserId.size() != 0) {
            queryWrapper.in("ta.draft_id", groupByUserId.stream().map(Allot::getDraftId).collect(Collectors.toList()));
            queryWrapper.eq("ta.status_code", STATUS_PPT_AUDIO_AUVELEADER_SEND);//1017
            IPage<Audio> pageInfo = audioService.listPage(page, queryWrapper);
            PageInfo pageInfo1 = new PageInfo(pageInfo);

            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", pageInfo1);
            return prefix + "worker/unAllotToMaker";
        }else{
            queryWrapper.lambda().eq(Audio::getStatusCode, StatusWriter.ERROR);
            IPage<Audio> pageInfo = audioService.page(page, queryWrapper);
            PageInfo pageInfo1 = new PageInfo(pageInfo);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", pageInfo1);
            return prefix + "worker/unAllotToMaker";
        }
    }

    /**
     * @Author 张雪
     * @Description 已分配音频到音视频制作人
     * @Date 2019/12/9 20:08
     **/
    @RequestMapping("allotedToMaker")
    public String allotedToMaker(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(audio.getAudioUrl())) {
            queryWrapper = queryWrapper.like("audio_url", audio.getAudioUrl());
        }
        if (!ObjectUtils.isEmpty(audio.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time", audio.getSubmitTime());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioPerson())) {
            queryWrapper = queryWrapper.like("audio_person", audio.getAudioPerson());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioLength())) {
            queryWrapper = queryWrapper.like("audio_length", audio.getAudioLength());
        }
        if (!ObjectUtils.isEmpty(audio.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete", audio.getIsDelete());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.lambda().between(Audio::getSubmitTime, DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        queryWrapper.lambda().orderByDesc(Audio::getCreateTime);
        queryWrapper.lambda().orderByDesc(Audio::getCreateTime);
        SysUser userIdByUserName = draftService.getUserIdByUserName(Utility.getCurrentUsername());
        List<Allot> draftByUserId = draftService.getDraftByUserId(userIdByUserName.getId());
        if (draftByUserId.size() != 0) {
            queryWrapper.in("ta.draft_id", draftByUserId.stream().map(Allot::getDraftId).collect(Collectors.toList()));
            queryWrapper.eq("ta.status_code", STATUS_PPT_AUDIO_AUVEREADER_SEND);//1018
            IPage<Audio> pageInfo = audioService.pageList(page, queryWrapper);
            PageInfo pageInfo1 = new PageInfo(pageInfo);


            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", pageInfo1);
            return prefix + "worker/alloted";
        }else{
            queryWrapper.lambda().eq(Audio::getStatusCode, StatusWriter.ERROR);
            IPage<Audio> pageInfo = audioService.page(page, queryWrapper);
            PageInfo pageInfo1 = new PageInfo(pageInfo);

            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", pageInfo1);
            return prefix + "worker/alloted";
        }
    }

    /**
     * @return
     * @Author 张雪
     * @Description 待制作音转视
     * @Date 2019/12/16 14:37
     * @Param
     **/
    @RequestMapping("unMakeAudio")
    public String unMakeAudio(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(audio.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id", audio.getDraftId());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioUrl())) {
            queryWrapper = queryWrapper.like("audio_url", audio.getAudioUrl());
        }
        if (!ObjectUtils.isEmpty(audio.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time", audio.getSubmitTime());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioPerson())) {
            queryWrapper = queryWrapper.like("audio_person", audio.getAudioPerson());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioLength())) {
            queryWrapper = queryWrapper.like("audio_length", audio.getAudioLength());
        }
        if (!ObjectUtils.isEmpty(audio.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code", audio.getStatusCode());
        }
        if (!ObjectUtils.isEmpty(audio.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete", audio.getIsDelete());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.lambda().between(Audio::getSubmitTime, DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        queryWrapper.lambda().orderByDesc(Audio::getCreateTime);
        SysUser userIdByUserName = audioService.getUserIdByUserName(Utility.getCurrentUsername());
        List<Allot> draftByUserId = audioService.getDraftByAllotnoId(userIdByUserName.getId());
        if (draftByUserId.size() != 0) {
            queryWrapper.in("ta.draft_id", draftByUserId.stream().map(Allot::getDraftId).collect(Collectors.toList()));
            queryWrapper.eq("ta.status_code", STATUS_PPT_AUDIO_AUVEREADER_SEND);//1018
            IPage<Audio> pageInfo = audioService.listPage(page, queryWrapper);;
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "maker/unMake";
        } else {
            queryWrapper.lambda().eq(Audio::getStatusCode, StatusWriter.ERROR);
            IPage<Audio> pageInfo = audioService.page(page, queryWrapper);

            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "maker/unMake";
        }
    }

    /**
     * @Author 张雪
     * @Description 点击跳转到detailAudio.html--音频
     * @Date 2019/12/16 14:47
     **/
    @GetMapping("detailAudio/{id}")
    public String detailAudio(Model model, @PathVariable("id") Long id) {
        model.addAttribute("audio", audioService.getById(id));
        return prefix + "maker/detailAudio";
    }


    /**
     * @Author//宋昱
     * @Description //
     * 音频校对人
     * 待审核音频
     * @Date 2019/12/16 20:10
     **/

    @RequestMapping("audioCheckPeople")
    public String audioCheckPeople(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<Audio>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<Audio>();
        if (!ObjectUtils.isEmpty(audio.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id", audio.getDraftId());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioUrl())) {
            queryWrapper = queryWrapper.like("audio_url", audio.getAudioUrl());
        }
        if (!ObjectUtils.isEmpty(audio.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time", audio.getSubmitTime());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioPerson())) {
            queryWrapper = queryWrapper.like("audio_person", audio.getAudioPerson());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioLength())) {
            queryWrapper = queryWrapper.like("audio_length", audio.getAudioLength());
        }
        if (!ObjectUtils.isEmpty(audio.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code", audio.getStatusCode());
        }
        if (!ObjectUtils.isEmpty(audio.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete", audio.getIsDelete());
        }

        queryWrapper.lambda().orderByDesc(Audio::getCreateTime);
        SysUser sysUser = audioService.getUserByUserName(Utility.getCurrentUsername());
        List<Allot> groupByUserId = audioService.getAllotDraftIdByUserId(sysUser.getId());

        if (groupByUserId.size() != 0) {
            if (!ObjectUtils.isEmpty(submitTimeSpace)){
                queryWrapper.between("ta.submit_time", DateUtil.getStart(submitTimeSpace)
                        ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
            }

            queryWrapper.in("ta.draft_id",groupByUserId.stream().map(Allot::getDraftId).collect(Collectors.toList()));
            queryWrapper.eq("ta.status_code", StatusConstant.STATUS_AUDIO_SUBMIT);
            IPage<Audio> pageInfo = audioService.listPage(page, queryWrapper);

            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "checkPeopleList";
        } else {
            queryWrapper.lambda().eq(Audio::getStatusCode, StatusWriter.ERROR);
            IPage<Audio> pageInfo = audioService.page(page, queryWrapper);

            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "checkPeopleList";
        }
//        //获取当前的登陆的用户名
//        String Username = Utility.getCurrentUsername();
//        //根据用户名获取校对人user_id
//        Long userIdByUsernameAudio = draftService.getUserIdByUsernameAudio(Username);
//        //找到下面的制作人提交的音频
//        List<Long> list = audioService.selectIdByAudio(userIdByUsernameAudio);
//        queryWrapper.in("id", list);
//        queryWrapper.lambda().eq(Audio::getStatusCode, StatusConstant.STATUS_AUDIO_SUBMIT);
//        queryWrapper.lambda().orderByDesc(Audio::getCreateTime);
//        IPage<Audio> pageInfo = audioService.page(page, queryWrapper);
//        model.addAttribute("submitTimeSpace", submitTimeSpace);
//        model.addAttribute("searchInfo", audio);
//        model.addAttribute("pageInfo", new PageInfo(pageInfo));
//        return prefix + "checkPeopleList";
    }

    /**
     * 单个审核
     * @param id
     * @return
     */
    @RequestMapping("checkSuccess")
    @ResponseBody
    public AjaxResult checkSuccess(Long id,Long draftId,Draft draft) {
        Draft byId = draftService.getById(draftId);
        byId.setDraftText(draft.getDraftText());
        byId.setDraftTitle(draft.getDraftTitle());
        byId.setDraftNum(draft.getDraftNum());
        byId.setFileName(draft.getFileName());
        draftService.updateById(byId);
        //获取当前的登陆的用户名
        String Username = Utility.getCurrentUsername();
        //根据用户名获取校对人user_id
        Long userIdByUsernameAudio = draftService.getUserIdByUsernameAudio(Username);
        Audio audio = new Audio();
        audio.setId(id);
        audio.setStatusCode(STATUS_AUDIO_SUCCESS);
        audioService.updateById(audio);
        //往check表插数据
        Check check = new Check();
        check.setDraftId(draftId);
        check.setUserId(userIdByUsernameAudio);
        check.setPreStatusCode(STATUS_AUDIO_SUBMIT);
        check.setIsPass(AUDIO_PASS);
        check.setOverStatusCode(STATUS_AUDIO_SUCCESS);
        checkService.save(check);
        applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_CHECK_YES)
                .setDraftId(draftId)
                .setPrimaryState(STATUS_AUDIO_SUBMIT)
                .setAfterState(STATUS_AUDIO_SUCCESS)
                .setGroupId(audioService.getById(id).getGroupId()));
        return this.success();
    }
    /**
     * @Author//宋昱
     * @Description //音频校对人
     * 获取 拒绝 id
     * @Date 2019/12/20 15:15
     */
    @GetMapping("checkFailBefore/{id}")
    public String checkFailBefore(@PathVariable("id") Long id, Model model) {
        log.info("===========failedBefore=============>{}", id);
        model.addAttribute("id", id);
        return prefix + "checkAudioFail";
    }

    /**
     * 刘雪奇
     * 音频校对人
     * 驳回
     */
    @PostMapping("checkAudioFail")
    @ResponseBody
    public AjaxResult checkAudioFail(Long draftId,Long audioId,String reason,String draftTitle,String draftText,Long draftNum,String fileName) {
        Draft byId = draftService.getById(draftId);
        byId.setDraftTitle(draftTitle);
        byId.setDraftText(draftText);
        byId.setDraftNum(draftNum);
        byId.setFileName(fileName);
        draftService.updateById(byId);

        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        Audio audio = audioService.getById(audioId);
        Check check = new Check();
        check.setIsPass(true);
        Long rolesId = sysUserRolesMapper.selectByUserId(audioService.selectIdByUsername(Utility.getCurrentUsername())).get(0).getRolesId();//获取登陆者角色id
        if (rolesId == com.mbyte.easy.common.constant.SysRole.AUDIO_PROOFREADER){
            audio.setStatusCode(StatusConstant.STATUS_AUDIO_FAIL);//2013
            check.setPreStatusCode(StatusConstant.STATUS_AUDIO_SUBMIT);//1010
            check.setOverStatusCode(STATUS_AUDIO_FAIL);//2013
        }else if (rolesId == com.mbyte.easy.common.constant.SysRole.AUDIO_VIDEO_CHECK_LEADER){
            audio.setStatusCode(StatusConstant.LEADER_CHECK_FAIL);//2014
            check.setPreStatusCode(StatusConstant.STATUS_AUDIO_SUCCESS);//1013
            check.setOverStatusCode(LEADER_CHECK_FAIL);//2014
        }

        audio.setLastOperator(audioService.selectIdByUsername(Utility.getCurrentUsername()));
        queryWrapper.in("id",audioId);
        audioService.update(audio,queryWrapper);

        check.setUserId(audioService.getUserByUserName(Utility.getCurrentUsername()).getId());
        check.setDraftId(draftService.getOne(new QueryWrapper<Draft>().eq("id",draftId)).getId());
        check.setReason(reason);
        check.setCreateTime(LocalDateTime.now());
        check.setUpdateTime(LocalDateTime.now());
        audioService.insertCheck(check);

        applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_CHECK_NO)
                .setDraftId(draftId)
                .setPrimaryState(check.getPreStatusCode())
                .setAfterState(check.getOverStatusCode())
                .setReason(reason)
                .setGroupId(audio.getGroupId()));
        return AjaxResult.success();
    }

    /**
     * 音视频校对组长修改 --牛英健--
     * @param draftId
     * @param draft
     * @return
     */
    @PostMapping("update")
    @ResponseBody
    public AjaxResult update(Long draftId,Draft draft){
        Draft draft1 = draftService.getById(draftId);
        draft1.setDraftText(draft.getDraftText());
        draft1.setDraftTitle(draft.getDraftTitle());
        draft1.setDraftNum(draft.getDraftNum());
        draft1.setFileName(draft.getFileName());
        draftService.updateById(draft1);
        applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_EDIT)
                .setDraftId(draftId));
        return AjaxResult.success();
    }

//    @GetMapping("checkFailBefore/{id}")
//    public String checkFailBefore(Model model, @PathVariable("id") Long id, Check check, Audio audio) {
//        //获取当前的登陆的用户名
//        String Username = Utility.getCurrentUsername();
//        //根据用户名获取校对人user_id
//        Long userIdByUsernameAudio = draftService.getUserIdByUsernameAudio(Username);
//        audio.setId(id);
//        audio.setStatusCode(STATUS_AUDIO_FAIL);
//        audioService.updateById(audio);
//        //用的张雪的方法根据id获取draftid
//        Long draftId = audioService.selectDraftIdById(id);
//        check.setDraftId(draftId);
//        check.setUserId(userIdByUsernameAudio);
//        check.setPreStatusCode(STATUS_AUDIO_SUBMIT);
//        check.setIsPass(AUDIO_UNPASS);
//        check.setOverStatusCode(STATUS_AUDIO_FAIL);
//        model.addAttribute("audio", audioService.getById(id));
//        return prefix + "checkAudioFail";
//    }

    /**
     * @Author//宋昱
     * @Description //在check表插入
     * @Date 2019/12/17 21:12
     **/
    @PostMapping("checkFail")
    @ResponseBody
    public AjaxResult checkFail(Check check) {
        return toAjax(checkService.save(check));
    }

    /**
     * @Author//宋昱
     * @Description //展示音频校对人审核通过的音频
     * @Date 2019/12/17 23:11
     **/
    @RequestMapping("SuccessList")
    public String SuccessList(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<Audio>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<Audio>();
        if (!ObjectUtils.isEmpty(audio.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id", audio.getDraftId());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioUrl())) {
            queryWrapper = queryWrapper.like("audio_url", audio.getAudioUrl());
        }
        if (!ObjectUtils.isEmpty(audio.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time", audio.getSubmitTime());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioPerson())) {
            queryWrapper = queryWrapper.like("audio_person", audio.getAudioPerson());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioLength())) {
            queryWrapper = queryWrapper.like("audio_length", audio.getAudioLength());
        }
        if (!ObjectUtils.isEmpty(audio.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code", audio.getStatusCode());
        }
        if (!ObjectUtils.isEmpty(audio.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete", audio.getIsDelete());
        }

        queryWrapper.lambda().orderByDesc(Audio::getCreateTime);
        //获取当前的登陆的用户名
        String Username = Utility.getCurrentUsername();
        //根据用户名获取校对人user_id
        Long userIdByUsernameAudio = draftService.getUserIdByUsernameAudio(Username);
        List<Allot> groupByUserId = audioService.getAllotDraftIdByUserId(userIdByUsernameAudio);
        if (groupByUserId.size() != 0){
            if (!ObjectUtils.isEmpty(submitTimeSpace)){
                queryWrapper.between("ta.submit_time", DateUtil.getStart(submitTimeSpace)
                        ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
            }

            queryWrapper.in("ta.draft_id", groupByUserId.stream().map(Allot::getDraftId).collect(Collectors.toList()));
            queryWrapper.eq("ta.status_code", STATUS_AUDIO_SUCCESS);
            IPage<Audio> pageInfo = audioService.listPage(page, queryWrapper);

            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "checkSuccessList";
        }else{
            queryWrapper.lambda().eq(Audio::getStatusCode, StatusWriter.ERROR);
            IPage<Audio> pageInfo = audioService.page(page, queryWrapper);

            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "checkSuccessList";
        }
//        List<Long> list = audioService.selectIdByAudio(userIdByUsernameAudio);
//        queryWrapper.in("id", list);
//        queryWrapper.lambda().eq(Audio::getStatusCode, STATUS_AUDIO_SUCCESS);
//
//        IPage<Audio> pageInfo = audioService.page(page, queryWrapper);
//        model.addAttribute("submitTimeSpace", submitTimeSpace);
//        model.addAttribute("searchInfo", audio);
//        model.addAttribute("pageInfo", new PageInfo(pageInfo));
//        return prefix + "checkSuccessList";
    }

    /**
     * 刘雪奇
     * 音频校对人
     * 已驳回音频页面
     */
    @RequestMapping("FailList")
    public String FailList(Model model, @RequestParam(value= "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(audio.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id", audio.getDraftId());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioUrl())) {
            queryWrapper = queryWrapper.like("audio_url", audio.getAudioUrl());
        }
        if (!ObjectUtils.isEmpty(audio.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time", audio.getSubmitTime());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioPerson())) {
            queryWrapper = queryWrapper.like("audio_person", audio.getAudioPerson());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioLength())) {
            queryWrapper = queryWrapper.like("audio_length", audio.getAudioLength());
        }
        if (!ObjectUtils.isEmpty(audio.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code", audio.getStatusCode());
        }
        if (!ObjectUtils.isEmpty(audio.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete", audio.getIsDelete());
        }

        queryWrapper.lambda().orderByDesc(Audio::getCreateTime);
        //获取当前的登陆的用户名
        String Username = Utility.getCurrentUsername();
        //根据用户名获取校对人user_id
        Long userIdByUsernameAudio = draftService.getUserIdByUsernameAudio(Username);
        List<Allot> groupByUserId = audioService.getAllotDraftIdByUserId(userIdByUsernameAudio);
        if (groupByUserId.size() != 0) {
            if (!ObjectUtils.isEmpty(submitTimeSpace)){
                queryWrapper.between("ta.submit_time", DateUtil.getStart(submitTimeSpace)
                        ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
            }
            queryWrapper.in("ta.draft_id", groupByUserId.stream().map(Allot::getDraftId).collect(Collectors.toList()));
            queryWrapper.eq("ta.status_code", STATUS_AUDIO_FAIL);
            IPage<Audio> pageInfo = audioService.listPage(page, queryWrapper);

            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "checkFailList";
        }else{
            queryWrapper.lambda().eq(Audio::getStatusCode, StatusWriter.ERROR);
            IPage<Audio> pageInfo = audioService.page(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "checkFailList";
        }

//        List<Long> list = audioService.selectIdByAudio(userIdByUsernameAudio);
//        queryWrapper.in("id", list);
//        queryWrapper.lambda().eq(Audio::getStatusCode, STATUS_AUDIO_FAIL);
//
//        IPage<Audio> pageInfo = audioService.page(page, queryWrapper);
//        model.addAttribute("submitTimeSpace", submitTimeSpace);
//        model.addAttribute("searchInfo", audio);
//        model.addAttribute("pageInfo", new PageInfo(pageInfo));
//        return prefix + "checkFailList";
    }

    /**
     * 刘雪奇
     * 音频校对人
     * 被驳回音频
     */
    @RequestMapping("APeopleBeFailed")
    public String APeopleBeFailed(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(audio.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id", audio.getDraftId());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioUrl())) {
            queryWrapper = queryWrapper.like("audio_url", audio.getAudioUrl());
        }
        if (!ObjectUtils.isEmpty(audio.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time", audio.getSubmitTime());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioPerson())) {
            queryWrapper = queryWrapper.like("audio_person", audio.getAudioPerson());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioLength())) {
            queryWrapper = queryWrapper.like("audio_length", audio.getAudioLength());
        }
        if (!ObjectUtils.isEmpty(audio.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code", audio.getStatusCode());
        }
        if (!ObjectUtils.isEmpty(audio.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete", audio.getIsDelete());
        }
        queryWrapper.lambda().orderByDesc(Audio::getCreateTime);
        SysUser sysUser = audioService.getUserByUserName(Utility.getCurrentUsername());
        List<Allot> groupByUserId = audioService.getAllotDraftIdByUserId(sysUser.getId());
        if (groupByUserId.size() != 0) {
            queryWrapper.in("ta.draft_id",groupByUserId.stream().map(Allot::getDraftId).collect(Collectors.toList()));
            queryWrapper.eq("ta.status_code", StatusConstant.LEADER_CHECK_FAIL);//2014
            IPage<Audio> pageInfo = audioService.listPage(page,queryWrapper);


            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "VPeopleBeFailed";
        } else {
            queryWrapper.lambda().eq(Audio::getStatusCode, StatusWriter.ERROR);
            IPage<Audio> pageInfo = audioService.page(page,queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "VPeopleBeFailed";
        }
    }

    /**
     * 刘雪奇
     * 音频校对人查看被驳回理由
     */
    @GetMapping("leaderFailedReason/{id}")
    public String leaderFailedReason(@PathVariable("id") Long id, Model model) {
        List<Check> checkById = audioService.getCheckById(id);
         for (int i = 0; i < checkById.size(); i++) {
             if (audioService.getById(id).getLastOperator() == checkById.get(i).getUserId()) {
                 model.addAttribute("check",checkById.get(i).getReason());
                 return prefix + "leaderReason";
             }
         }
        return prefix + "leaderReason";
    }

    /**
     * 刘雪奇
     * 音频校对人查看被驳回理由
     */
    @GetMapping("leaderFailedReasonw/{id}")
    public String leaderFailedReasonw(@PathVariable("id") Long id, Model model) {
        List<Check> checkById = audioService.getCheckById(id);
        for (int i = 0; i < checkById.size(); i++) {
            if (draftService.getById(id).getLastOperator() == checkById.get(i).getUserId()) {
                model.addAttribute("check",checkById.get(i).getReason());
                return prefix + "leaderReason";
            }
        }
        return prefix + "leaderReason";
    }

    /**
     * 刘雪奇
     * 音频校对人
     * 单个通过
     */
    @GetMapping("CheckSuccessById/{id}")
    @ResponseBody
    public AjaxResult CheckSuccessById(@PathVariable("id") Long id){
        log.info("===========>{}",id);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        Audio audio = new Audio();
        audio.setStatusCode(StatusPPTAudio.STATUS_AUDIO_AUDIOREADER_SUCCESS);
        audio.setLastOperator(audioService.selectIdByUsername(Utility.getCurrentUsername()));
        queryWrapper.in("id",id);
        audioService.update(audio,queryWrapper);

        Check check =new Check();
        check.setIsPass(false);
        check.setPreStatusCode(StatusPPTAudio.STATUS_AUDIO_AUDIORECODER_UPLOAD);
        check.setOverStatusCode(StatusPPTAudio.STATUS_AUDIO_AUDIOREADER_SUCCESS);
        check.setUserId(audioService.getUserByUserName(Utility.getCurrentUsername()).getId());
        check.setDraftId(id);
        audioService.insertCheck(check);

        return toAjax(true);
    }

    /**
     * @Author//宋昱
     * @Description //展示音频校对人审核未通过的音频
     * @Date 2019/12/17 23:11
     * 音频录制人
     * 被驳回页面
     **/
    @RequestMapping("audio_FailList")
    public String audio_FailList(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<Audio>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<Audio>();
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.between("ta.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }

        queryWrapper.lambda().eq(Audio::getAudioPerson,Utility.getCurrentUsername());
        queryWrapper.eq("ta.status_code",StatusConstant.STATUS_AUDIO_FAIL);
        queryWrapper.lambda().orderByDesc(Audio::getCreateTime);



        IPage<Audio> pageInfo = audioService.listPage(page,queryWrapper);
        model.addAttribute("submitTimeSpace",submitTimeSpace);
        model.addAttribute("searchInfo",audio);
        model.addAttribute("pageInfo",new PageInfo(pageInfo));

        return prefix + "failed";


    }

    /**
     * 刘雪奇
     * 音频录制人
     * 上传音频
     */
    @PostMapping("saveAudio")
    @ResponseBody
    public AjaxResult saveAudio(@RequestParam("file") MultipartFile file, @RequestParam("id") Long id) {
        if (file != null) {
            String url = OssFileUtils.uploadSingleFile(file);
            QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(Audio::getDraftId, id);
            Audio audio = audioService.getOne(queryWrapper);
            if(audio == null){
                audio = new Audio();
            }
            audio.setDraftId(id);
            audio.setAudioUrl(url);
            audio.setStatusCode(STATUS_AUDIO_ALLOTED_PEOPLE);//1009
            audio.setAudioPerson(Utility.getCurrentUsername());
            audio.setSubmitTime(LocalDateTime.now());
            audio.setCreateTime(LocalDateTime.now());
            audio.setUpdateTime(LocalDateTime.now());
            audio.setLastOperator(audioService.selectIdByUsername(Utility.getCurrentUsername()));
            audio.setGroupId(draftService.getById(id).getGroupId());
            audioService.saveOrUpdate(audio);
//            UpdateWrapper<Audio> update = new UpdateWrapper<>();
//            update.eq("draft_id",id);
//            audioService.update(audio,update);
            String actionContent = "";
            if(draftService.selectRoleId() == SysRole.AUDIO_PRODUCER){
                actionContent = "音频制作人上传音频";
            }else{
                actionContent = "稿件转视制作人上传音频";
            }
            applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_AUDIO)
                    .setDraftId(id).setGroupId(audioService.GetGroupIdById(id).getGroupId())
                    .setActionContent(actionContent));

            return AjaxResult.success(url);
        }


//        if (file != null) {
//            log.info("=========AudioId" + id);
//            String url = OssFileUtils.uploadSingleFile(file);
//            log.info("=========url", url);
//            Audio audio = new Audio();
//            audio.setId(id);
//            audio.setAudioUrl(url);
//            audio.setAudioPerson(Utility.getCurrentUsername());
//            audio.setStatusCode(StatusConstant.STATUS_AUDIO_SUBMIT);//1010
//            audio.setSubmitTime(LocalDateTime.now());
//            audio.setCreateTime(LocalDateTime.now());
//            audio.setUpdateTime(LocalDateTime.now());
//            audio.setGroupId(audioService.selectAGroupIdById(id).getGroupId());
//
//
//        }
        return AjaxResult.error();
    }

    /**
     * 刘雪奇
     * 音频录制人
     * 发布音频
     */
    @PostMapping("addAudio")
    @ResponseBody
    public AjaxResult addAudio(@RequestParam("id") Long id,Draft draft1) {
        log.info("draft123"+draft1);
        Draft draft = draftService.getById(id);
        draft.setDraftTitle(draft1.getDraftTitle());
        draft.setDraftText(draft1.getDraftText());
        draft.setDraftNum(draft1.getDraftNum());
        draft.setFileName(draft1.getFileName());
        draft.setStatusCode(StatusConstant.STATUS_AUDIO_SUBMIT);//1010
        draftService.updateById(draft);

        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Audio::getDraftId, id);
        Audio audio = audioService.getOne(queryWrapper);
        if(audio != null){
            audio.setStatusCode(StatusConstant.STATUS_AUDIO_SUBMIT);
            audioService.updateById(audio);
        }
        applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_OTHER)
                .setDraftId(id)
                .setActionContent("音频录制人发布")
                .setPrimaryState(StatusConstant.STATUS_AUDIO_ALLOTED_PEOPLE)
                .setAfterState(StatusConstant.STATUS_AUDIO_SUBMIT)
                .setGroupId(audio.getGroupId()));
        return AjaxResult.success();
    }

    /**
     * 刘雪奇
     * 音频录制人查看驳回理由
     */
    @GetMapping("audioFailedReasonBefore/{id}")
    public String audioFailedReasonBefore(@PathVariable("id") Long id, Model model) {
        List<Check> checkById = audioService.getCheckById(id);
        log.info("checkById==================>>{}",checkById);
        log.info("当前登录人：===========",audioService.getUserByUserName(Utility.getCurrentUsername()).getId());
        log.info("最后操作人ID============",audioService.getById(id).getLastOperator());
        for (int i = 0; i < checkById.size(); i++) {
            if (audioService.getById(id).getLastOperator() == checkById.get(i).getUserId()) {
                model.addAttribute("check",checkById.get(i).getReason());
                return prefix + "AudioFailedReasonBefore";
            }
        }
        return prefix + "AudioFailedReasonBefore";
    }

    /**
   * @Author//宋昱
    * @Description //音频录制人制作音频
    * @Date 2019/12/20 15:16
           **/
//    @PostMapping("addAudio")
//    @ResponseBody
//    public AjaxResult documentMethod(@RequestParam("file") MultipartFile file, @RequestParam("id") Long id,@RequestParam("groupId") String groupId) {
//        //操作draft表
//        Draft draft=new Draft();
//        draft.setId(id);
//        draft.setStatusCode(STATUS_AUDIO_SUBMIT);
//        draftService.updateById(draft);
//        //操作audio表
//        //获取url
//        String url= OssFileUtils.uploadSingleFile(file);
//        //获取当前的登陆的用户名
//        String Username= Utility.getCurrentUsername();
//        Audio audio =new Audio();
//        audio.setDraftId(id);
//        audio.setAudioUrl(url);
//        audio.setAudioPerson(Username);
//        audio.setStatusCode(STATUS_AUDIO_SUBMIT);
//        String groupID=groupId.substring(AAA);
//        audio.setGroupId(groupID);
//        audioService.save(audio);
//        if (file != null) {
//            return AjaxResult.success();
//        }
//        return AjaxResult.error();
//    }
    /**
    * @Author//宋昱
     * @Description //待审核的音频列表
     * @Date 2019/12/19 16:35
            **/
    @RequestMapping("uncheckList")
    public String uncheckList(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.between("ta.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }

        //获取当前的登陆的用户名
        String Username= Utility.getCurrentUsername();

        queryWrapper.lambda().eq(Audio::getAudioPerson,Username);
        queryWrapper.eq("ta.status_code", STATUS_AUDIO_SUBMIT);//1010
        queryWrapper.lambda().orderByDesc(Audio::getCreateTime);


        IPage<Audio> pageInfo = audioService.listPage(page, queryWrapper);
        PageInfo pageInfo1 = new PageInfo(pageInfo);
        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("searchInfo", audio);
        model.addAttribute("pageInfo", pageInfo1);
        return prefix + "uncheckList";
    }
    /**
    * @Author//宋昱
     * @Description //音频制作人审核通过界面
     * @Date 2019/12/19 17:23
            **/
    @RequestMapping("successCheckList")
    public String successCheckList(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(audio.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id", audio.getDraftId());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioUrl())) {
            queryWrapper = queryWrapper.like("audio_url", audio.getAudioUrl());
        }
        if (!ObjectUtils.isEmpty(audio.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time", audio.getSubmitTime());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioPerson())) {
            queryWrapper = queryWrapper.like("audio_person", audio.getAudioPerson());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioLength())) {
            queryWrapper = queryWrapper.like("audio_length", audio.getAudioLength());
        }
        if (!ObjectUtils.isEmpty(audio.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code", audio.getStatusCode());
        }
        if (!ObjectUtils.isEmpty(audio.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete", audio.getIsDelete());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.between("ta.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        //获取当前的登陆的用户名
        String Username= Utility.getCurrentUsername();
        //找出录制人为自己的，状态为提交完成的audio列表
        queryWrapper.lambda().eq(Audio::getAudioPerson,Username);
        queryWrapper.in("ta.status_code", SUCCESS_FINAL,STATUS_AUDIO_SUCCESS);
        queryWrapper.lambda().orderByDesc(Audio::getCreateTime);
        IPage<Audio> pageInfo = audioService.listPage(page, queryWrapper);

        PageInfo pageInfo1 = new PageInfo(pageInfo);
        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("searchInfo", audio);
        model.addAttribute("pageInfo", pageInfo1);
        return prefix + "successCheckList";
    }
    /**
    * @Author//宋昱
     * @Description //音频审核失败的界面
     * @Date 2019/12/19 21:11
            **/
    @RequestMapping("failCheckList")
    public String failCheckList(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(audio.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id", audio.getDraftId());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioUrl())) {
            queryWrapper = queryWrapper.like("audio_url", audio.getAudioUrl());
        }
        if (!ObjectUtils.isEmpty(audio.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time", audio.getSubmitTime());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioPerson())) {
            queryWrapper = queryWrapper.like("audio_person", audio.getAudioPerson());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioLength())) {
            queryWrapper = queryWrapper.like("audio_length", audio.getAudioLength());
        }
        if (!ObjectUtils.isEmpty(audio.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code", audio.getStatusCode());
        }
        if (!ObjectUtils.isEmpty(audio.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete", audio.getIsDelete());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.lambda().between(Audio::getSubmitTime, DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        //获取当前的登陆的用户名
        String Username= Utility.getCurrentUsername();
        //找出录制人为自己的，状态为提交完成的audio列表
        queryWrapper.lambda().eq(Audio::getAudioPerson,Username);
        queryWrapper.lambda().eq(Audio::getStatusCode, SUCCESS_FINAL);
        IPage<Audio> pageInfo = audioService.page(page, queryWrapper);
        PageInfo pageInfo1 = new PageInfo(pageInfo);
        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("searchInfo", audio);
        model.addAttribute("pageInfo", pageInfo1);
        return prefix + "failCheckList";
    }
    /**
     * @Author//宋昱
     * 音视频校对组长
     * 未审核的音频
     **/
    @RequestMapping("LeaderCheckList")
    public String LeaderCheckList(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                  @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                  String submitTimeSpace,Audio audio,String groupIIID) {

        Page<Audio> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ta.status_code", StatusConstant.STATUS_AUDIO_SUCCESS);//1013
        QueryWrapper<Audio> videoQueryWrapper = new QueryWrapper<>();
        videoQueryWrapper.eq("status_code", StatusConstant.STATUS_AUDIO_SUCCESS);//1013
        videoQueryWrapper.groupBy("group_id");
        QueryWrapper<Audio> videos = new QueryWrapper<>();
        videos.eq("group_id",audio.getGroupId());
        List<Audio> list = audioService.list(videos);

        if(list != null){
            model.addAttribute("videoListSize", draftService.getNeedCheckSize(audio.getGroupId(),true,STATUS_DRAFT_AUDIO_ALLOT,
                    STATUS_AUDIO_ALLOTED_PEOPLE,STATUS_AUDIO_SUBMIT
            ));
        }
        List<Long> childrenIdByParentId = audioService.getChildrenIdByParentId(audioService.getUserByUserName(Utility.getCurrentUsername()).getId());

        QueryWrapper<Group> groupQueryWrapper = new QueryWrapper<>();
        if (childrenIdByParentId != null) {
            childrenIdByParentId.add(-1L);
            groupQueryWrapper = groupQueryWrapper.in("user_id", childrenIdByParentId);
        }

        List<Group> groupList = groupService.list(groupQueryWrapper);
        List<String> stringList = new ArrayList<>(groupList.size());
        if (groupList.size() > 0) {
            for (int i = 0; i < groupList.size(); i++) {
                stringList.add(groupList.get(i).getGroupId());
            }
            if(!CollectionUtils.isEmpty(stringList)) {
                log.info("stringList"+stringList);
                videoQueryWrapper = videoQueryWrapper.in("group_id", stringList);
            }
        }
        List<Audio> videoList = audioService.list(videoQueryWrapper);
        if (videoList!=null){
            for(Audio video1:videoList){
                for (Group group : groupList) {
                    if(video1.getGroupId().equals(group.getGroupId())){
                        video1.setGroupName(group.getName());
                    }
                }
            }
            model.addAttribute("videoList", videoList);
        }else{
            model.addAttribute("videoList", 0);
        }
//        model.addAttribute("videoList", videoList);
//        model.addAttribute("videoListSize", list.size());
        if (!ObjectUtils.isEmpty(audio.getGroupId())) {
            queryWrapper = queryWrapper.eq("ta.group_id", audio.getGroupId());
            queryWrapper.lambda().orderByDesc(Audio::getCreateTime);

            IPage<Audio> pageInfo = audioService.listPage(page, queryWrapper);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "LeaderCheckList";
        } else {
            queryWrapper.in("group_id", stringList);
            QueryWrapper<Audio> audioQueryWrapper = new QueryWrapper<>();
            audioQueryWrapper.eq("status_code", StatusWriter.ERROR);

            queryWrapper.lambda().orderByDesc(Audio::getCreateTime);
            IPage<Audio> pageInfo = audioService.page(page, audioQueryWrapper);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "LeaderCheckList";
        }

    }

    /**
    * @Author//宋昱
     * @Description
     * 音频校对组长
     * 批量审核通过
     * @Date 2019/12/21 0:55
            **/
    @PostMapping("leaderCheckSuccess")
    @ResponseBody
    public AjaxResult leaderCheckSuccess(@RequestBody List<Long> ids) {

        log.info("==============>{}",ids);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        Audio audio = new Audio();
        audio.setStatusCode(StatusConstant.SUCCESS_FINAL);//1014
        audio.setLastOperator(audioService.selectIdByUsername(Utility.getCurrentUsername()));
        queryWrapper.in("id",ids);
        audioService.update(audio, queryWrapper);

        for (int i = 0; i < ids.size(); i++) {
            Check check = new Check();
            check.setIsPass(false);
            check.setPreStatusCode(StatusConstant.STATUS_AUDIO_SUCCESS);//1013
            check.setOverStatusCode(StatusConstant.SUCCESS_FINAL);//1016
            check.setUserId(audioService.getUserByUserName(Utility.getCurrentUsername()).getId());
            check.setDraftId(audioService.getOne(new QueryWrapper<Audio>().eq("id",ids.get(i))).getId());
            audioService.insertCheck(check);

            applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_CHECK_YES)
                    .setDraftId(audioService.getOne(new QueryWrapper<Audio>().eq("id",ids.get(i))).getId())
                    .setGroupId(audioService.getOne(new QueryWrapper<Audio>().eq("id",ids.get(i))).getGroupId())
                    .setPrimaryState(StatusConstant.STATUS_AUDIO_SUCCESS)
                    .setAfterState(StatusConstant.SUCCESS_FINAL));
        }
        return toAjax(true);
    }

    /**
     * 刘雪奇
     * 音频校对组长
     * 已通过的音频
     */
    @RequestMapping("audioLeaderSuccess")
    public String audioLeaderSuccess(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(audio.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id", audio.getDraftId());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioUrl())) {
            queryWrapper = queryWrapper.like("audio_url", audio.getAudioUrl());
        }
        if (!ObjectUtils.isEmpty(audio.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time", audio.getSubmitTime());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioPerson())) {
            queryWrapper = queryWrapper.like("audio_person", audio.getAudioPerson());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioLength())) {
            queryWrapper = queryWrapper.like("audio_length", audio.getAudioLength());
        }
        if (!ObjectUtils.isEmpty(audio.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code", audio.getStatusCode());
        }
        if (!ObjectUtils.isEmpty(audio.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete", audio.getIsDelete());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.lambda().between(Audio::getSubmitTime, DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }

        SysUser sysUser = audioService.getUserByUserName(Utility.getCurrentUsername());
        List<Allot> groupByUserId = audioService.getAllotDraftIdByUserId(sysUser.getId());
        if (groupByUserId.size() != 0) {
            queryWrapper.in("ta.draft_id", groupByUserId.stream().map(Allot::getDraftId).collect(Collectors.toList()));
            queryWrapper.eq("ta.status_code", StatusConstant.LEADER_CHECK_SUCCESS);//1014
            queryWrapper.lambda().orderByDesc(Audio::getCreateTime);

            IPage<Audio> pageInfo = audioService.listPage(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo",audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "audioLeaderSuccessReviewed";
        } else {
            queryWrapper.lambda().eq(Audio::getStatusCode, StatusWriter.ERROR);
            queryWrapper.lambda().orderByDesc(Audio::getCreateTime);

            IPage<Audio> pageInfo = audioService.page(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo",audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "audioLeaderSuccessReviewed";
        }
    }

    /**
     * 刘雪奇
     * 音频校对组长
     * 驳回的音频
     */
    @RequestMapping("audioLeaderFailed")
    public String audioLeaderFailed(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String createTimeSpace, String updateTimeSpace, Audio audio) {
        Page<Audio> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(audio.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id", audio.getDraftId());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioUrl())) {
            queryWrapper = queryWrapper.like("audio_url", audio.getAudioUrl());
        }
        if (!ObjectUtils.isEmpty(audio.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time", audio.getSubmitTime());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioPerson())) {
            queryWrapper = queryWrapper.like("audio_person", audio.getAudioPerson());
        }
        if (!ObjectUtils.isEmpty(audio.getAudioLength())) {
            queryWrapper = queryWrapper.like("audio_length", audio.getAudioLength());
        }
        if (!ObjectUtils.isEmpty(audio.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code", audio.getStatusCode());
        }
        if (!ObjectUtils.isEmpty(audio.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete", audio.getIsDelete());
        }
        queryWrapper.lambda().orderByDesc(Audio::getCreateTime);
        SysUser sysUser = audioService.getUserByUserName(Utility.getCurrentUsername());
        List<Allot> groupByUserId = audioService.getAllotDraftIdByUserId(sysUser.getId());
        if (groupByUserId.size() != 0) {
            queryWrapper.in("ta.draft_id", groupByUserId.stream().map(Allot::getDraftId).collect(Collectors.toList()));
            queryWrapper.eq("ta.status_code", StatusConstant.LEADER_CHECK_FAIL);
            IPage<Audio> pageInfo = audioService.listPage(page, queryWrapper);

            model.addAttribute("submitTimeSpace",submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "audioLeaderFailedReviewed";
        } else {
            queryWrapper.lambda().eq(Audio::getStatusCode, StatusWriter.ERROR);
            IPage<Audio> pageInfo = audioService.page(page, queryWrapper);

            model.addAttribute("submitTimeSpace",submitTimeSpace);
            model.addAttribute("searchInfo", audio);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "audioLeaderFailedReviewed";
        }
    }

    /**
     * 刘雪奇
     * 音视频校对组长
     * 获取 拒绝 id
     **/
    @GetMapping("leaderCheckFail/{id}")
    public String leaderCheckFail(Model model, @PathVariable("id") Long id) {
        model.addAttribute("id",id);
        return prefix + "leaderCheckFail";
    }

    /**
     * 刘雪奇
     * 音频校对组长
     * 拒绝
     **/
    @PostMapping("leaderCheckFail")
    @ResponseBody
    public AjaxResult leaderCheckFail(Long id, String reason) {
        QueryWrapper<Audio> queryWrapper = new QueryWrapper<>();
        Audio audio = new Audio();
        audio.setStatusCode(LEADER_CHECK_FAIL);
        audio.setLastOperator(audioService.selectIdByUsername(Utility.getCurrentUsername()));
        queryWrapper.in("id", id);
        audioService.update(audio, queryWrapper);

        Check check = new Check();
        check.setIsPass(true);
        check.setPreStatusCode(StatusConstant.STATUS_AUDIO_SUCCESS);//1013
        check.setOverStatusCode(LEADER_CHECK_FAIL);//2014
        check.setUserId(audioService.getUserByUserName(Utility.getCurrentUsername()).getId());
        check.setDraftId(audioService.getOne(new QueryWrapper<Audio>().eq("id",id)).getId());
        check.setReason(reason);
        check.setCreateTime(LocalDateTime.now());
        check.setUpdateTime(LocalDateTime.now());
        audioService.insertCheck(check);
        return toAjax(true);
    }

    /**
     * 刘雪奇
     * 查看详情
     */
    @GetMapping("doneAudio/{id}")
    public String doneAudio(Model model,@PathVariable("id")Long id){
        model.addAttribute("draft",draftService.getById(id));
        return prefix+"look";
    }
}
